package com.cloudxingkong.dianyinke.Student.Adapter;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudxingkong.dianyinke.R;
import com.cloudxingkong.dianyinke.Student.bean.VideoTeacherEntity;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by ningfei on 2016/3/22.
 */
public class VideoTeachingAdapter extends BaseAdapter {
    private List<VideoTeacherEntity.ListBean> datas;
    private Context context;
    public VideoTeachingAdapter(List<VideoTeacherEntity.ListBean> datas, Context context) {
        this.datas = datas;
        this.context = context;


    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.videoteaching_item, null);
            holder = new ViewHolder();
            holder.tv_name = (TextView) convertView.findViewById(R.id.tvVideo_memname);
            holder.tv_title = (TextView) convertView.findViewById(R.id.tvVodeo_title);
            holder.tv_views = (TextView) convertView.findViewById(R.id.tvVideo_views);
            holder.tv_lisks = (TextView) convertView.findViewById(R.id.tvVideo_lisks);
            holder.image_dadada = (ImageView) convertView.findViewById(R.id.image_dadada);
            holder.riv_headX = (CircleImageView) convertView.findViewById(R.id.riv_headX);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_name.setText(datas.get(position).getType() + "");
        holder.tv_title.setText(datas.get(position).getTitle() + "");
        holder.tv_lisks.setText(datas.get(position).getViews() + "");
        holder.tv_views.setText(datas.get(position).getLikes() + "");

        ImageLoader.getInstance().displayImage(datas.get(position).getAvatar(), holder.riv_headX);
        ImageLoader.getInstance().displayImage(datas.get(position).getCoverpic(),holder.image_dadada);
//        //获取视频缩略图
//        MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
//        File file=new File("/storage/sdcard/image1");
//        if(file.exists()){
//            mediaMetadataRetriever.setDataSource(file.getAbsolutePath());//设置数据源为该文件对象指定的绝对路径
//            Bitmap bitmap=mediaMetadataRetriever.getFrameAtTime();//获得视频第一帧的Bitmap对象
//            if(bitmap!=null){
//               holder.image_dadada.setImageBitmap(bitmap);//设置ImageView显示的图片
//                Toast.makeText(context, "获取视频缩略图成功", Toast.LENGTH_SHORT).show();//获取视频缩略图成功，弹出消息提示框
//            }else{
//                Toast.makeText(context, "获取视频缩略图失败", Toast.LENGTH_SHORT).show();//获取视频缩略图失败，弹出消息提示框
//            }
//        }else{
//            Toast.makeText(context, "文件不存在", Toast.LENGTH_SHORT).show();//文件不存在时，弹出消息提示框
//        }
        return convertView;
    }

    private class ViewHolder {
        TextView tv_name, tv_title, tv_lisks, tv_views;
        ImageView image_dadada;
        CircleImageView riv_headX;
    }
}
